package com.gg.user.gguser.service.impl;

import com.gg.user.gguser.dao.GgHomeMapper;
import com.gg.user.gguser.dao.GgSearchMapper;
import com.gg.user.gguser.service.GgHomeService;
import com.gg.vo.return_format;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yangxinlei
 * @date 2020/5/22
 */
@Service
public class GgHomeServiceImpl implements GgHomeService {

    @Autowired
    private GgHomeMapper ggHomeMapper;

    @Autowired
    private GgSearchMapper ggSearchMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Object getHomeTop(HttpServletResponse response, HttpServletRequest request) throws Exception {
        try {
            // 机构数量---->公司身份
            Integer getHometopUserGrade = ggHomeMapper.getHometopUserGrade();

            // 员工数量---->公司身份下绑定的   超管客服没有这个
            Integer getHometopUserBinding = ggHomeMapper.getHometopUserBinding();

            //合同数量
            Integer getHomeTopContract = ggHomeMapper.getHomeTopContract();

            //公库数量
            Integer getHomeTopInformation = ggHomeMapper.getHomeTopInformation();

            // 商机数量
            Integer getHomeTopBusinessopportunity = ggHomeMapper.getHomeTopBusinessopportunity();

            //系统收录信息数量
            Integer getHomeTopCompany = ggHomeMapper.getHomeTopCompany();

            Map date = new HashMap<String,String>();
            date.put("getHometopUserGrade",getHometopUserGrade);
            date.put("getHometopUserBinding",getHometopUserBinding);
            date.put("getHomeTopContract",getHomeTopContract);
            date.put("getHomeTopInformation",getHomeTopInformation);
            date.put("getHomeTopBusinessopportunity",getHomeTopBusinessopportunity);
            date.put("getHomeTopCompany",getHomeTopCompany);
            return return_format.return_format_All(0,date,"");
        }catch (Exception e){
            return return_format.return_format_error(100002,"服务器出错！");
        }

    }

    /**
     * 中间信息简介
     * @param response
     * @param request
     * @return
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Object getHomeCountInformation(HttpServletResponse request, HttpServletRequest response) {
        try {
            // 第一部分 今日联系
            SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd");
            String dataString = formatter.format(new Date(System.currentTimeMillis()));
            List<Map<Object,Object>> mapContactToday = ggHomeMapper.contactToday(dataString);

            //第二部分 近期到期合同
            List<Map<Object,Object>> mapContractDataobjectCount = ggHomeMapper.getGgContractDataobjectCount(dataString);

            //第三部分 最新收录信息
            List<Map<Object,Object>> ListCompanySearch =  ggSearchMapper.getCompanySearch(1,10);

            Map date = new HashMap<String,String>();
            date.put("mapContactToday", mapContactToday);
            date.put("mapContractDataobjectCount", mapContractDataobjectCount);
            date.put("ListCompanySearch", ListCompanySearch);
            return return_format.return_format_All(0,date,"");
        }catch (Exception e){
            return return_format.return_format_error(100002,"服务器出错！");
        }
    }

    @Override
    public Object getHomeBottomChart(HttpServletResponse request, HttpServletRequest response) {
        // 第一个统计图  信息，商机，合同比例
        Integer businessopportunityCount = ggHomeMapper.businessopportunityCount(); // 全部商机
        Integer contractCount = ggHomeMapper.contractCount(); // 全部合同
        Integer informationCount = ggHomeMapper.informationCount(); // 全部信息


        // 第二个统计图

        // 第三个统计图
        return null;
    }
}
